<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/web/ui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/web/ui/css/public.css" media="all">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
    <script src="/web/js/vue2.js"></script>
    <script src="/web/js/axios.min.js"></script>
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>
<body>

<div id="app">
    <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="企业名称">
            <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="主营项目">
            <el-input v-model="form.business"></el-input>
        </el-form-item>
        <el-form-item label="联系人">
            <el-input v-model="form.contact"></el-input>
        </el-form-item>
        <el-form-item label="联系方式">
            <el-input v-model="form.tel"></el-input>
        </el-form-item>
        <el-form-item label="用户名">
            <el-input v-model="form.loginName"></el-input>
        </el-form-item>
        <el-form-item label="登录密码">
            <el-input v-model="form.loginPwd"></el-input>
        </el-form-item>

        <el-form-item label="首页推荐">
            <el-radio-group v-model="form.isRecomment">
                <el-radio label="0">推荐</el-radio>
                <el-radio label="1">不推荐</el-radio>
            </el-radio-group>
        </el-form-item>

        <el-form-item label="VIP开始">
            <el-col>
                <el-form-item>
                    <el-date-picker style="width: 40%" type="text" disabled v-model="form.createTime"/>
                </el-form-item>

            </el-col>
            <el-col class="line" :span="2">-</el-col>
            持续 {{form.duration}}月
        </el-form-item>

        <el-form-item label="企业类别">
            <el-select v-model="form.type" placeholder="请选择类别">
                <el-option label="中国入驻企业" value="中国入驻企业"></el-option>
                <el-option label="俄罗斯入驻企业" value="俄罗斯入驻企业"></el-option>
                <el-option label="事业合作企业" value="事业合作企业"></el-option>
            </el-select>
        </el-form-item>

        <el-form-item label="企业主图">
            <el-upload
                    class="upload-demo"
                    drag
                    action="http://localhost:8800/file/upload/firm"
                    :auto-upload="true"
                    :on-success="uploadSuccess"
                    :limit="limit">
                <i class="el-icon-upload"></i>
                <img style="width: 25%" v-if="form.picPath" :src="form.picPath">
                <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                <div class="el-upload__tip" slot="tip">只能上传jpg/png文件，且不超过500kb</div>
            </el-upload>
        </el-form-item>

        <el-form-item label="企业简介">
            <el-input type="textarea" v-model="form.smInfo"></el-input>
        </el-form-item>

        <el-form-item label="详细介绍">
            <el-input type="textarea" v-model="form.detailInfo"></el-input>
        </el-form-item>


        <el-form-item>
            <el-button type="primary" @click="doSubmit">修改</el-button>
            <el-button @click="doCancel">取消</el-button>
        </el-form-item>

    </el-form>
</div>

<script src="/web/ui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>

<script>

    const vm = new Vue({
        el: "#app",
        data() {
            return {
                limit: 1,
                form: {
                    vipId: "",
                    firmId: "",
                    name: "",
                    business: "",
                    contact: "",
                    tel: "",
                    loginName: "",
                    loginPwd: "",
                    createTime: "",
                    duration: "",
                    isRecomment: "0",
                    type: "",
                    picPath: "",
                    smInfo: "",
                    detailInfo: ""
                },
            }
        },
        methods: {
            uploadSuccess(res, file, fileList) {
                // console.log(res.data);
                this.form.picPath = res.data;
                axios.post("/firm/vip/updatePic", {
                    id: this.form.vipId,
                    picPath: this.form.picPath
                });
            },
            doSubmit() {
                // 关闭当前页面
                window.close();
                this.handleUpdate();
                // console.log(this.form.type);

                // 刷新父页面
                window.parent.location.reload();
            },
            doCancel() {
                window.close();
                // 刷新父页面
                window.parent.location.reload();
            },
            // 更新
            handleUpdate() {
                axios.post("/firm/vip/update", {
                    vipId: this.form.vipId,
                    firmId: this.form.id,
                    firmName: this.form.name,
                    business: this.form.business,
                    contact: this.form.contact,
                    tel: this.form.tel,
                    loginName: this.form.loginName,
                    loginPwd: this.form.loginPwd,
                    createTime: this.form.createTime,
                    duration: this.form.duration,
                    isRecomment: this.form.isRecomment,
                    type: this.form.type,
                    picPath: this.form.picPath,
                    smInfo: this.form.smInfo,
                    detailInfo: this.form.detailInfo,
                })
            }
        },
        async mounted() {
            const firm = JSON.parse(localStorage.getItem("t"));
            let vipFirm = await axios.get("/firm/vip/detail?firmId=" + firm.id);
            // console.log(vipFirm.data);
            vipFirm = vipFirm.data;

            this.form.id = firm.id;
            this.form.name = firm.name;
            this.form.business = firm.business;
            this.form.contact = firm.contact;
            this.form.tel = firm.tel;
            this.form.loginName = firm.loginName;
            this.form.loginPwd = firm.loginPwd;

            this.form.vipId = vipFirm.data.id;
            this.form.createTime = vipFirm.data.createTime;
            this.form.duration = vipFirm.data.duration;
            this.form.isRecomment = vipFirm.data.isRecomment.toString();
            this.form.type = vipFirm.data.type;
            this.form.picPath = vipFirm.data.picPath;
            this.form.smInfo = vipFirm.data.smInfo;
            this.form.detailInfo = vipFirm.data.detailInfo;
            // console.log(this.form.createTime);
            localStorage.removeItem("t");
        }
    });


</script>
</body>
</html>